$(document).ready(function() {
	
	// Prepare jtable plugin
	$('#StudentTableContainer').jtable({
		title : 'Liste des macro-taches',
		selecting : true,
		paging : true, // Enables paging
		pageSize : 10, // Actually this is not needed since default value is
		// 10.
		sorting : true, // Enables sorting
		defaultSorting : 'Nom ASC', // Optional. Default sorting on first load.

		actions : {
			listAction : '/piloteOrdo/tache/getAllTache',
			createAction : '/piloteOrdo/tache/addMacroTache',
			updateAction : '/piloteOrdo/tache/updateTache',
			deleteAction : '/piloteOrdo/tache/deleteTache'
		},
		fields : {
			Id : {
				key : true,
				create : false,
				edit : false,
				list : false
			},
			Intitule : {
				title : 'Intitule',
				width : '23%',
				inputClass: 'validate[required]'
			},
//			Description : {
//				title : 'Description',
//				width : '23%',
//				inputClass: 'validate[required]'
//			},
			Phase : {
				title : 'Phase',
				width : '23%',
				options : '/piloteOrdo/taches/phaseOption',
				inputClass: 'validate[required]'
			},
			Zone : {
				title : 'Zone',
				inputClass: 'validate[required]'	
			},
			Specialite : {
				title : 'Specialite',
				options : '/piloteOrdo/taches/specOption'
			}

		},
		rowInserted : function(event, data) {
			$('#StudentTableContainer').jtable('selectRows', data.row);
			console.log("records inserted");
		},
		// Register to selectionChanged event to hanlde events
		recordAdded : function(event, data) {
			// after record insertion, reload the records
			$('#StudentTableContainer').jtable('load');
		},
		recordUpdated : function(event, data) {
			// after record updation, reload the records
			$('#StudentTableContainer').jtable('load');
		},
		
		//Initialize validation logic when a form is created
        formCreated: function (event, data) {
            data.form.validationEngine();
        },
        //Validate form when it is being submitted
        formSubmitting: function (event, data) {
            return data.form.validationEngine('validate');
        },
        //Dispose validation logic when form is closed
        formClosed: function (event, data) {
            data.form.validationEngine('hide');
            data.form.validationEngine('detach');
        }

	});

	// Load student list from server
	$('#StudentTableContainer').jtable('load');
});